﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NConsoler;
using log4net;
using MVCGen.Core;
using MVCGen.Mappings;
using NHibernate.Cfg.MappingSchema;

namespace MVCGen {
	public class Program {
		private static ILog log = LogManager.GetLogger("MVCGen");

		// --------------------------------------------------------------------
		// Application entry point
		// --------------------------------------------------------------------

		[STAThread]
		public static void Main(string[] args) {
			Consolery.Run(typeof(Program), args);
		}

		// --------------------------------------------------------------------
		// Actions
		// --------------------------------------------------------------------

		[Action]
		public static void Init([Optional("sqlite")] String db) {
			DbType dbType = DbType.SQlite;
			try {
				dbType = (DbType)Enum.Parse(typeof(DbType), db, true);
			} catch (ArgumentException) {
				log.Error(String.Format("Invalid database type {0}", db));
			}
			log.Info("Initializing NHibernate...");
			log.Info(String.Format("Using database {0}", dbType));
			log.Info("Done");
		}

		[Action]
		public static void Controller([Required] String entity) {
			log.Info(String.Format("Generating CRUD controller for class {0}...", entity));
			log.Info("Done");
		}

		[Action]
		public static void Service([Required] String entity) {
			log.Info(String.Format("Generating CRUD service for class {0}...", entity));
			log.Info("Done");
		}

		[Action]
		public static void Dao([Required] String entity) {
			log.Info(String.Format("Generating CRUD DAO for class {0}...", entity));
			log.Info("Done");
		}

		[Action]
		public static void Scaffold([Required] String entity) {
			log.Info(String.Format("Scaffolding {0}...", entity));
			log.Info("Done");
		}

		[Action]
		public static void Test() {
		}
	}
}
